package com.slfx.idgen.server.enums;

import lombok.Getter;

/**
 * 入库类型
 *
 * @author slfx
 * @date 2022/11/21
 */
@Getter
public enum BizTypeEnum {

    /**
     * 验收
     */
    CHECK_ACCEPT(1, "YS","验收"),

    /**
     * 调拨
     */
    TRANSFER(2, "DB","调拨"),

    /**
     * 盘点
     */
    STOCKTAKING(3,"PD", "盘点入库"),

    ;

    private final Integer value;

    private final String code;
    private final String desc;

    BizTypeEnum(Integer value,String code, String desc) {
        this.value = value;
        this.code = code;
        this.desc = desc;
    }

    public static BizTypeEnum parseValue(Integer value) {
        if (value == null) {
            return null;
        }
        for (BizTypeEnum e : BizTypeEnum.values()) {
            if (value.equals(e.value)) {
                return e;
            }
        }
        return null;
    }

    public static BizTypeEnum ofCode(String code) {
        if (code == null) {
            throw new RuntimeException("code为空！");
        }
        for (BizTypeEnum e : BizTypeEnum.values()) {
            if (code.equals(e.code)) {
                return e;
            }
        }
        throw new RuntimeException("code找不到对应的枚举类！");
    }
}
